//
//  HJAddFriendCell.m
//  KaiChat
//
//  Created by lx on 2023/10/21.
//

#import "HJAddFriendCell.h"
#import "QMUIButton.h"

@interface HJAddFriendCell()

@property (nonatomic, weak) UIImageView *avatarImageView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *uidLabel;
@property (nonatomic, weak) QMUIButton *addButton;

@end

@implementation HJAddFriendCell

- (void)settingSubView {
    [super settingSubView];
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *avatarImageView = [UIImageView addToView:self.contentView];
    avatarImageView.addCornerRadius(20);
    avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.centerY.offset(0);
        make.width.height.offset(40);
    }];
 
    UILabel *nameLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImageView.mas_right).offset(10);
        make.top.equalTo(avatarImageView).inset(2);
        make.right.mas_lessThanOrEqualTo(-100);
    }];
    
    UILabel *uidLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    [uidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel);
        make.bottom.equalTo(avatarImageView).inset(2);
    }];
    
    UIImageView *arrowImageView = [UIImageView addToView:self.contentView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(uidLabel.mas_right).offset(5);
        make.centerY.equalTo(uidLabel);
    }];
    
    QMUIButton *addButton = [QMUIButton buttonWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.whiteColor title:@"Add"];
    addButton.addCornerRadius(5);
    addButton.hidden = YES;
    addButton.backgroundColor = UIColor.tj_mainColor;
    [addButton addTarget:self action:@selector(didClickAddButton) forControlEvents:UIControlEventTouchUpInside];
    [addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.centerY.offset(0);
        make.width.offset(72);
        make.height.offset(30);
    }];
 
    _addButton = addButton;
    _avatarImageView = avatarImageView;
    _nameLabel = nameLabel;
    _uidLabel = uidLabel;
}

- (void)didClickAddButton {
    if (_model.relationship != -1) {
        return;
    }
    if (_didClickAddButtonBlock) {
        _didClickAddButtonBlock();
    }
}


- (void)setModel:(HJChatUserModel *)model {
    _model = model;
    
    [_avatarImageView tj_setImageWithUrl:model.avatar placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    _nameLabel.text = model.nickname;
    _uidLabel.text = model.uid;
    _addButton.userInteractionEnabled = YES;

    if (_model.relationship == 2) {
        if (model.way == 1) {//自己发起的
            _addButton.hidden = NO;
            _addButton.userInteractionEnabled = NO;
            [_addButton setTitle:@"Waiting" forState:UIControlStateNormal];
            [_addButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        } else {
            _addButton.hidden = YES;
        }
    } else if (_model.relationship == -1) {
        [_addButton setTitle:@"add" forState:UIControlStateNormal];
        [_addButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _addButton.hidden = NO;
    } else {
        _addButton.hidden = YES;
    }
}



@end
